<div ng-controller="Approval_PurchasingDetailsC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">审批详情</h1>
    </div>

    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive">
                <form name="form" class="form-validation">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <div class="form-group">
                                <label>供应商</label>
                                <input type="text" class="form-control" readonly="readonly" value="{{orderdetaildata.Provider.Name}}">
                            </div>
                            <div class="form-group">
                                <label>收货仓库</label>
                                <input type="text" class="form-control" readonly="readonly" value="{{orderdetaildata.ToDepot.Name}}">
                            </div>
                            <!--<div class="form-group">-->
                                <!--<label>商品打款账户</label>-->
                                <!--<input type="text" class="form-control" readonly="readonly" value="{{orderdetaildata.Account}}">-->
                            <!--</div>-->
                            <!--<div class="form-group">-->
                                <!--<label>运费打款账户</label>-->
                                <!--<input type="text" class="form-control" readonly="readonly" value="{{orderdetaildata.DeliveryAccount}}">-->
                            <!--</div>-->
                            <div class="form-group">
                                <label>每吨运费</label>
                                <input type="text" class="form-control" readonly="readonly" value="{{orderdetaildata.DeliveryPrice}}">
                            </div>
                            <div class="form-group">
                                <label>联系人信息</label>
                                <input type="text" class="form-control" readonly="readonly" value="{{orderdetaildata.Contact}}">
                            </div>
                            <div class="form-group">
                                <label>备注</label>
                                <input type="text" class="form-control" readonly="readonly" value="{{orderdetaildata.Remarks}}">
                            </div>
                            <div class="form-group">
                                <label>创建人：</label>
                                <span>{{orderdetaildata.Creater.Name}}</span>
                            </div>
                            <!--<div class="form-group">-->
                            <!--<label>变更记录：</label>-->
                            <!--<ul>-->
                            <!--<li ng-repeat="item in orderdetaildata.Records">-->
                            <!--<label ng-if="item.Price != 0">{{item.Price}}/</label>{{item.Remarks}}/{{item.CreateTime}}-->
                            <!--</li>-->
                            <!--</ul>-->
                            <!--</div>-->
                            <div class="form-group">
                                <label>采购单状态：</label>
                                <span ng-if="orderdetaildata.State == 0">待确认</span>
                                <span ng-if="orderdetaildata.State == 1">审批中</span>
                                <span ng-if="orderdetaildata.State == 2">采购中</span>
                                <span ng-if="orderdetaildata.State == 3">取消</span>
                                <span ng-if="orderdetaildata.State == 4">完成采购</span>
                                <span ng-if="orderdetaildata.State == 5">入库审批</span>
                                <span ng-if="orderdetaildata.State == 6">待确认</span>
                            </div>
                        </div>
                        <div class="container-fluid text-center bg-light lter" >
                            <div class="row">
                                <h3 style="display: inline-block;margin: 0 auto">采购单商品列表</h3>
                            </div>
                        </div>
                        <div class="container-fluid">
                            <div class="row" style="border-bottom: red solid 1px" ng-repeat="item in orderdetaildata.Goodses">
                                <div class="col-xs-12 col-md-12">
                                    <div>名称/材质/规格：{{item.Commodity.Name}}/{{item.Commodity.Standard}}/{{item.Commodity.Format}}</div>
                                    <div>单价：{{item.Price | number:2}}/t</div>
                                    <div>数量：{{item.Count}}</div>
                                    <div>总质量：{{item.Weight | number:3}}t</div>
                                    <div>总价：{{item.Price | number:2}}*{{item.Weight | number:3}}t={{item.Price*item.Weight | number:2}}</div>
                                </div>
                            </div>
                            <div class="row text-left">
                                <h4 style="display: inline-block">总价：{{orderdetaildata.Total | number:2}}</h4>
                            </div>
                            <div class="row text-left">
                                <h4 style="display: inline-block">预计运费价格：{{orderdetaildata.DeliveryPriceTotal | number:2}}</h4>
                            </div>
                        </div>
                        <div style="padding: 0px 15px">
                            <span><b>流程类型：</b>{{data.TypeName}}</span><br>
                            <span><b>内容：</b>{{data.Title}}</span><br>
                            <span><b>申请人：</b>{{data.Creater.Name}}</span><br>
                            <span><b>审批人：</b>{{data.NowApproverName}}</span><br>

                            <label>审批意见</label>{{data.Remarks}}<br>
                            <div ng-if="data.ApprovalState==1||data.ApprovalState==0">
                                <input ng-disabled="item.ApprovalState==2||item.ApprovalState==3" ng-model="data.opinion" type="text" class="form-control">
                                <button type="button" class="btn btn-success" ng-click="DoAppr(true)" ng-hide="item.ApprovalState==2||item.ApprovalState==3">通过</button>
                                <button type="button" class="btn btn-warning" ng-click="DoAppr(false)" ng-hide="item.ApprovalState==2||item.ApprovalState==3">驳回</button>
                                <button type="button" class="btn btn-default" ng-click="goorderList()">返回列表</button>
                                <span ng-show="item.ApprovalState==2">已通过</span>
                                <span ng-show="item.ApprovalState==3">已驳回</span>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        </div>
    </div>

<script>
    angular.module('app') //非标优惠
            .controller("Approval_PurchasingDetailsC", function($scope, $state, $http,$stateParams) {
                $http({
                    url: "/api/Approval?id=" + $stateParams.id,
                    method: "GET"
                    // data: { id: $stateParams.id}
                })
                        .then(function(res) {
                            $scope.data = res.data;
                            console.log($scope.data);
                            $http({
                                url: "../api/Purchase/" + $scope.data.Tag,
                                method: "GET"
                            })
                                    .then(function (res) {
                                        $scope.orderdetaildata = res.data;
                                        console.log($scope.orderdetaildata);
                                    })
                                    .then(function (error) {
                                        if (error) {
                                            console.log("error");
                                        }
                                    });
                        })
                        .then(function(error) {
                            if (error) {
                                alert("数据获取失败");
                            }
                        });

                //返回列表
                $scope.goorderList = function(){
                    $state.go('app.Approval_Index');
                };
                $scope.DoAppr= function(isOk) {
                    $http.post("/api/Approval/Approval?id=" + $stateParams.id + "&pass=" + isOk + "&opinion=" + $scope.data.opinion)
                            .success(function() {
                                alert("审批完成");
                                $scope.goorderList();
                            }).error(function() {alert("处理失败")})
                    ;
                }
            });

</script>